package com.spark.demoim.utils

import android.content.res.TypedArray
import android.util.TypedValue
import com.spark.demoim.global.App

/**
 * Created by lenovo on 2017/8/15.
 */
class ResUtil {
    companion object {
        /**
         * 获取指定 attr 的 DimenSize 大小
         */
        fun getDimensionSizeFromAttr(style: Int, defValue: Int): Int {
            val attrs = intArrayOf(style)
            val typedArray = App.appContext!!.obtainStyledAttributes(style, attrs) as TypedArray
            val value = typedArray.getDimensionPixelSize(0, defValue)
            typedArray.recycle()
            println("【DimensionSizeFromAttr】 =【$value】")
            return value
        }

        fun getColorFromAttr(style: Int, defValue: Int): Int {
            val attrs = intArrayOf(style)
            val typedArray = App.appContext!!.obtainStyledAttributes(style, attrs) as TypedArray
            val value = typedArray.getColor(0, defValue)
            typedArray.recycle()
            println("【ColorFromAttr】 =【$value】")
            return value
        }
    }
}